<template>
  <div class="mirror-tab1">
    <p class="g-unit">单位: 元</p>
    <div class="tableBox">
      
      <el-table
        v-loading="tableLoading"
        :data="tableData"
        height="85vh"
        style="width: 100%"
        class="tableTh28"
        border
        stripe
        :span-method="arraySpanMethod"
        ref="table"
      >
        <el-table-column
          fixed
          label="实际/计划"
          prop="indexType"
          min-width="90"
        ></el-table-column>

        <el-table-column
          fixed
          label="正向/负向"
          prop="indexName"
          min-width="80"
        ></el-table-column>
        <el-table-column fixed label="项目" prop="itemName"> </el-table-column>
        <el-table-column
          :label="item.label"
          v-for="(item, index) in titles"
          :key="index"
          :prop="item.id"
          min-width="120"
        >
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { mergeSpan } from "@/utils/mixin";
export default {
  name: "incomeMirror-tab1",
  props: ["rowData1", "rawTime"],
  data() {
    return {
      tableData: [],
      tableLoading: true,
      spanArr: null,
      year: "",
      month: "",
      time: {},
      title1: [],
      title2: [],
      title3: [],
      subtype: "0",
      titles: [],
    };
  },

  methods: {
    //table合并行
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0 || columnIndex == 1) {
        return this.spanArr && this.spanArr[rowIndex][columnIndex];
      }
    },

    init() {
      let that = this,
        titles = that.rowData1.titleName.slice(3),
        titlesId = that.rowData1.titleId.slice(3),
        titleArr = [],
        titleInfo = [];

      that.tableData = that.rowData1.list;

      that.tableLoading = true;
      titlesId.map((it, i) => {
        let obj = {
          label: titles[i],
          id: it,
        };
        titleInfo.push(obj);
      });
      that.titles = titleInfo;
      if (that.rowData1 && that.rowData1.list.length) {
        that.spanArr = mergeSpan(that.rowData1.list, [
          "indexType",
          "indexName",
        ]);
      }

      that.$nextTick(() => {
        that.tableLoading = false;
        that.$refs.table.doLayout();
      });
    },
    AreaUnique(arr) {
      var arr1 = []; // 新建一个数组来存放arr中的值
      for (var i = 0, len = arr.length; i < len; i++) {
        if (arr1.indexOf(arr[i]) === -1) {
          arr1.push(arr[i]);
        }
      }
      return arr1;
    },
    formatArr(arr, num) {
      //最后返回的结果为一个二维数组
      var newArr = new Array(Math.ceil(arr.length / 2));
      for (let i = 0; i < newArr.length; i++) {
        newArr[i] = [];
      }
      for (let i = 0; i < arr.length; i++) {
        newArr[parseInt(i / num)][i % num] = arr[i];
      }
      return newArr;
    },
  },
};
</script>

<style lang="scss">
.mirror-tab1 {
  .cell {
    text-align: center;
  }
}
</style>